MASTER_ADDRESS=${1:-"172.19.182.191"}
KUBE_SSL_DIR="/etc/kubernetes/ssl"

cat <<EOF >/opt/kubernetes/cfg/kube-controller-manager
KUBE_LOGTOSTDERR="true"
KUBE_LOG_LEVEL="4"
KUBE_API_MASTER="${MASTER_ADDRESS}:8080"
KUBE_ADDRESS="127.0.0.1"
KUBE_ROOT_CA_FILE="${KUBE_SSL_DIR}/ca.pem"
KUBE_SERVICE_ACCOUNT_PRIVATE_KEY_FILE="${KUBE_SSL_DIR}/ca-key.pem"
EOF

cat <<EOF >/usr/lib/systemd/system/kube-controller-manager.service
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-controller-manager
ExecStart=/opt/kubernetes/bin/kube-controller-manager \
--logtostderr=\${KUBE_LOGTOSTDERR} \
--v=\${KUBE_LOG_LEVEL} \
--master=\${KUBE_API_MASTER} \
--address=\${KUBE_ADDRESS} \
--root-ca-file=\${KUBE_ROOT_CA_FILE} \
--service-account-private-key-file=\${KUBE_SERVICE_ACCOUNT_PRIVATE_KEY_FILE}

Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable kube-controller-manager
systemctl restart kube-controller-manager
systemctl status kube-controller-manager

kubectl get componentstatuses

echo -e "\033[42;37m==kube-controller-manager配置完成===============================================================================\033[0m"
